<template>
	<div>

		<div class="app-container">
			<TopInfo />

			<Search :lookup="data.lookup" @investigate="inves" />

			<div>
				<el-button type="primary" @click="getExport">{{ $t('machine.online.export')}}</el-button>
			</div>

		</div>

		<div class="app-container" v-loading="data.mtloading">
			<el-table :data="data.list" :header-cell-style="{ 'text-align': 'center' }"
				:cell-style="{ 'text-align': 'center' }" class="w-full" height="650">
				<el-table-column prop="machine_id" :label="$t('machine.code')" show-overflow-tooltip>
					<template #default="scope">
						{{ scope.row.machine_id || '--' }}
					</template>
				</el-table-column>

				<el-table-column prop="machine_name" :label="$t('machine.name')" show-overflow-tooltip>
					<template #default="scope">
						{{ scope.row.machine_name || '--' }}
					</template>
				</el-table-column>

				<el-table-column prop="channel_code" :label="$t('report.supplement.channelNum')" show-overflow-tooltip>
					<template #default="scope">
						{{ scope.row.channel_code || '--' }}
					</template>
				</el-table-column>

				<el-table-column prop="g_name" :label="$t('machine.goods.name')" show-overflow-tooltip>
					<template #default="scope">
						{{ scope.row.g_name || '--' }}
					</template>
				</el-table-column>

				<el-table-column prop="sku" label="SKU" show-overflow-tooltip>
					<template #default="scope">
						{{ scope.row.sku || '--' }}
					</template>
				</el-table-column>

				<el-table-column prop="before" :label="$t('report.supplement.beforeRestock')" show-overflow-tooltip>
					<template #default="scope">
						{{ scope.row.before || '0' }}
					</template>
				</el-table-column>

				<el-table-column prop="quantity" :label="$t('report.supplement.replenishment')" show-overflow-tooltip>
					<template #default="scope">
						{{ scope.row.quantity || '0' }}
					</template>
				</el-table-column>

				<el-table-column prop="after" :label="$t('report.supplement.afterRestock')" show-overflow-tooltip>
					<template #default="scope">
						{{ scope.row.after || '0' }}
					</template>
				</el-table-column>

				<el-table-column prop="creator_nickname" :label="$t('report.supplement.operator')" show-overflow-tooltip>
					<template #default="scope">
						{{ scope.row.creator_nickname || '--' }}
					</template>
				</el-table-column>

				<el-table-column prop="create_time" :label="$t('date.replenishTime')" show-overflow-tooltip>
					<template #default="scope">
						{{ getPlevel.gettime(scope.row.create_time, 3) }}
					</template>
				</el-table-column>

			</el-table>

			<PageNum :total="data.total" :page="data.suppent" @exposeData="current" @fraction="fraction" />

		</div>
		<exports :dialogVisible="dialogExport" @close="dialogExport = false" />
	</div>
</template>

<script lang="ts" setup>
import { useI18n } from 'vue-i18n' 
const { t: $t } = useI18n()
import TopInfo from '@/components/TopInfo/index.vue';
import Search from '@/components/Search/index.vue';
import PageNum from '@/components/PageNum/index.vue';
import getPlevel from '@/utils/level'
import { getreplenishmentList, replenishmentexport } from '@/api/report';
import { ElMessage, ElMessageBox } from "element-plus";
import exports from '@/components/export.vue';
const dialogExport = ref(false)
let data = reactive({
	mtloading: false, // 加载
	lookup: [ // 筛选栏
		{ title: $t('machine.code'), type: 'mId', value: '', key: 'm_id' },
		{ title: $t('machine.name'), type: 'input', value: '', key: 'machine_name' },
		{ title: $t('report.supplement.channelNum'), type: 'input', value: '', key: 'channel_code' },
		{ title: 'SKU', type: 'input', value: '', key: 'sku' },
	],
	suppent: { // 筛选数据
		m_id: '',
		machine_name: '',
		channel_code: '',
		sku: '',
		page: 1,
		pageNum: 15
	},
	total: 0, // 总条数

})

let getlist = () => {
	data.mtloading = true
	getreplenishmentList(data.suppent).then(res => {
		data.mtloading = false
		if (res.state == 200) {
			data.list = res.data.data
			data.total = res.data.total
		}
	})

}
let getExport = () => {
	ElMessageBox.confirm($t('message.isExport')).then(res => {
		replenishmentexport(data.suppent).then(res => {
			if (res.state == 200) {
				dialogExport.value = true
				getlist()
				return
			}
			ElMessage({
				message: $t('message.networkFailed'),
				type: 'error'
			})
		}).catch(err => {
			console.log(err)
		})
	}).catch(err => {
		console.log('取消')
	})
}
// 查询回调
let inves = (e) => {
	for (let key in e) {
		data.suppent[key] = e[key]
	}
	data.suppent.page = 1
	data.suppent.pageNum = 15
	getlist()
}



// 页数回调
let current = (e) => {
	data.suppent.page = e
	getlist()
}

// 条数回调
let fraction = (e) => {
	data.suppent.pageNum = e
	getlist()
}

getlist()

</script>
